/*
Copyright 2011, 2012 Alessandro Magnolo.

This file is part of Backlight Indicator.

Backlight Indicator is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Backlight Indicator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Backlight Indicator.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.magnolo.backlight_indicator;

import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.widget.TextView;

public class AboutDialogBuilder {
	public static AlertDialog create(Context context) throws NameNotFoundException {
		// Try to load the a package matching the name of our own package
		PackageInfo pInfo=context.getPackageManager().getPackageInfo(context.getPackageName(),
		   PackageManager.GET_META_DATA);
		String versionInfo=pInfo.versionName;

		String aboutTitle=context.getString(R.string.app_name)+" "+versionInfo;
		String aboutText="Shows an icon in the status bar to indicate whether the Pixel Qi screen backlight is on or off.\n\n"
		   +"User guide and updates:\nhttp://blog.magnolo.com/backlight-indicator\n\n"
		   +"Copyright © 2011, 2012 Alessandro Magnolo\n"+"Backlight Indicator is free software released under GPLv3";

		// Set up the TextView
		final TextView message=new TextView(context);
		// We'll use a spannablestring to be able to make links clickable
		final SpannableString s=new SpannableString(aboutText);

		// Set some padding
		message.setPadding(5, 5, 5, 5);
		// Set up the final string
		message.setText(s);
		// Now linkify the text
		Linkify.addLinks(message, Linkify.ALL);

		// text size
		message.setTextSize(20);
		message.setTextColor(Color.WHITE);

		return new AlertDialog.Builder(context).setTitle(aboutTitle).setCancelable(true).setIcon(R.drawable.ic_launcher)
		   .setPositiveButton(context.getString(android.R.string.ok), null).setView(message).create();
	}
}